package com.woniu.tms.openclass.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.woniu.tms.entity.Course;
import com.woniu.tms.entity.Room;
import com.woniu.tms.entity.User;
import com.woniu.tms.entity.UserRole;
import com.woniu.tms.entity.UserRoleExample;
import com.woniu.tms.entity.UserRoleExample.Criteria;
import com.woniu.tms.mapper.CourseMapper;
import com.woniu.tms.mapper.RoomMapper;
import com.woniu.tms.mapper.UserMapper;
import com.woniu.tms.mapper.UserRoleMapper;
import com.woniu.tms.openclass.service.openClassUserService;

@Service
public class openClassUserServiceImpl implements openClassUserService{
    @Autowired
    UserMapper userMapper;
	@Autowired
	UserRoleMapper userRoleMapper;
	@Autowired
	CourseMapper courseMapper;
	@Autowired
	RoomMapper roomMapper;
	
	
	@Override
	public List<UserRole> findAll() {
		List<User> list=userMapper.selectByExample(null);
		//存储角色id
		List<Integer> roleIdList=new ArrayList<Integer>();
		    for (User listes : list) {
		    	roleIdList.add(listes.getUid());
			}
		
		    UserRoleExample example=new UserRoleExample();
		    Criteria criteria = example.createCriteria();
		    criteria.andUidIn(roleIdList);
		    List<UserRole> UserRoleList = userRoleMapper.selectByExample(example);
		
		return UserRoleList;
	}


	@Override
	public List<Course> findCourse() {
		List<Course> CourseList = courseMapper.selectByExample(null);
		return CourseList;
	}


	@Override
	public List<Room> findRoom() {
		List<Room> roomList = roomMapper.selectByExample(null);
		return roomList;
	}


	@Override
	public List<UserRole> findByUid(Integer uid) {
		
		 UserRoleExample example=new UserRoleExample();
		 Criteria criteria = example.createCriteria();
		 criteria.andUidEqualTo(uid);
	     List<UserRole> UserRoleList = userRoleMapper.selectByExample(example); 
	     return UserRoleList;
	}
     
	
	
	
}
